/* 
 * Author: vdaras
 */


#ifndef FONT_H
#define	FONT_H

#include "../NonCopyable.h"
#include "SDL/SDL_ttf.h"
#if defined(_MSC_VER)
#include <memory>
#else
#include <auto_ptr.h>
#endif
#include <string>

/*
 * Class wrapping a TTF_Font. This class main constraint is that the TTF_Font's
 * instance should NEVER be NULL. So opening is allowed only during construction.
 * Before creating a font, TTF subsystem should be initialized!
 */

namespace sdl
{

class Color;
class Surface;
class TextImage;

class Font : public NonCopyable
{
private:
    TTF_Font *m_font;
    int m_fontAscent;
    int m_fontDescent;
    int m_fontHeight;
    int m_fontLineSkip;
    int m_averageAdvance;

public:
    Font(const std::string &path, int size);
    ~Font();

    //info routines
    int GetAscent();
    int GetDescent();
    int GetHeight();
    int GetLineSkip();
    int GetAverageAdvance();
    void TextSize(const std::string &text, int &width, int &height);
    void GlyphSize(Uint16 glyph, int &minX, int &maxX, int &minY, int &maxY, int &advance);

    bool RenderText(int x, int y, const std::string &text, const Color &color, Surface *target) const;
    bool Valid() const;
    std::auto_ptr< sdl::TextImage > GetImage(const std::string &text, const Color &color) const;
    
private:
    bool Open(const std::string &path, int size);
};

};

#endif	/* FONT_H */

